<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <h1>输入待办事项</h1>
        <input type="text" @keydown.enter="add" v-model="text">
        <h1>待办事项列表</h1>
        <ul v-if="todoList.length">
            <li v-for="(item,index) in todoList">
                <input type="checkbox" v-model="item.status" @click="done(index)">
                {{item.text}}
            </li>
        </ul>
        <h1>已完成</h1>
        <ul>
            <li v-for="(item,index) in doneList">
                <input type="checkbox" v-model="item.status" @click="todo(index)">
                {{item.text}}
                <button @click="del(index)">删除</button>
            </li>
        </ul>
        <!-- {
            status：false
            text:'内容'
        } -->
    </div>
    <script src="./vue.js"></script>
    <script>
        let vm = new Vue({
            el:'#app',
            data:{
                text:'',
                todoList:[],  //待办数组
                doneList:[]   //已完成数组
            },
            methods:{
                add(){
                    this.todoList.push({
                        text:this.text,
                        status:false
                    })
                    this.text = '';
                },
                done(index){
                    let target = this.todoList[index];
                    this.todoList.splice(index,1);
                    target.status = true;
                    this.doneList.push(target);
                },
                todo(index){
                    let target = this.doneList[index];
                    this.doneList.splice(index,1);
                    target.status = false;
                    this.todoList.push(target);
                },
                del(index){
                    this.doneList.splice(index,1);
                }
            }
        })
    </script>
</body>
</html>